// Fungerar. Producerar 2^31-2 slumptal.
#include <stdio.h>
#include <conio.h>

int rnd(int *seed){
  int seedv,seedh;
  seedv=*seed & 0x7FFF0000;
  seedv=16807*(seedv>>16);
  seedh=*seed & 0x0000FFFF;
  seedh=16807*seedh;
  *seed=((seedv & 0x00007FFF)<<16)+seedh;
  *seed=*seed+((seedv & 0xFFFF8000)>>15);
  if (*seed<0) *seed=(*seed & 0x7FFFFFFF)+1;
  return *seed;
}

int main(void){
  int seed,seed2,i,j,v=0;
  seed=1;
  j=rnd(&seed);
  do{
    i=rnd(&seed);
    v++;
    if(v%10000000==0) printf("*** %d\n",v);
  }while(i!=j);
  printf("%d (%d) (%d)",v,i);
  getch();
}
